#include <math.h>
#include <iostream>
#include <set>
#include <map>

using std::cout; 
using std::endl;
using std::set;
using std::map;

class Point
{

public:
    Point(double x, double y)
        : _x(x)
        , _y(y){}

    double getX() const{ return _x; }
    double getY() const{ return _y; }
    double getDistance() const{ return sqrt(hypot(_x, _y)); }


private:
    double _x{};
    double _y{};
};

bool operator<(const Point& lhs, const Point& rhs){
    if(lhs.getDistance() < rhs.getDistance()) { return true; }
    else if(lhs.getDistance() < rhs.getDistance()) { return false; }
    else if(lhs.getDistance() == rhs.getDistance()){
        if(lhs.getX() > rhs.getX()){ return true; }
        else if(lhs.getX() < rhs.getX()){ return false; }
        else if(lhs.getX() == rhs.getX()){
            if(lhs.getY() < rhs.getY()){ return true; }
            else{ return false; }
        }
    }
}

namespace std
{
template<>
struct less<Point>
{
    bool operator()(const Point& lhs, const Point& rhs) const{
        if(lhs.getDistance() < rhs.getDistance()) { return true; }
        else if(lhs.getDistance() < rhs.getDistance()) { return false; }
        else if(lhs.getDistance() == rhs.getDistance()){
            if(lhs.getX() > rhs.getX()){ return true; }
            else if(lhs.getX() < rhs.getX()){ return false; }
            else if(lhs.getX() == rhs.getX()){
                if(lhs.getY() < rhs.getY()){ return true; }
                else{ return false; }
            }
        }
    }
};
}

struct com
{
    bool operator()(const Point& lhs, const Point& rhs) const{
        if(lhs.getDistance() < rhs.getDistance()) { return true; }
        else if(lhs.getDistance() < rhs.getDistance()) { return false; }
        else if(lhs.getDistance() == rhs.getDistance()){
            if(lhs.getX() > rhs.getX()){ return true; }
            else if(lhs.getX() < rhs.getX()){ return false; }
            else if(lhs.getX() == rhs.getX()){
                if(lhs.getY() < rhs.getY()){ return true; }
                else{ return false; }
            }
        }
    }
};

int main(void)
{
    
    set<Point, com> s = {
        Point(1, 2),
        Point(-1, 2),
        Point(3, 4),
        Point(-1, -2),
        Point(1, 2),
        Point(5, 2),
        Point(1, -2),
    };


    for(auto& elem : s){
        cout << elem.getX() << " " << elem.getY() << endl;
    }
    return 0;
}